import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/routes/routePages.dart';
import '../../themes/appTheme.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

class StudentAppDrawer extends StatelessWidget {
  StudentAppDrawer({Key? key}) : super(key: key);

  List<Widget> _buildMenuItems() {
    List<Widget> menuItems = [];
    for (int i = 0; i < RoutePages.studentPageItems.length; i++) {
      if (i == 0) {
        menuItems.add(SizedBox(height: 50));
      }
      menuItems.add(Container(
        padding: const EdgeInsets.symmetric(horizontal: 10),
        child: PointerInterceptor(
          child: ListTile(
            selected: Get.currentRoute == RoutePages.studentPageItems[i].route,
            selectedTileColor: Get.isDarkMode
                ? Get.theme.primaryColor
                : Get.theme.primaryColorDark,
            leading: Icon(
              RoutePages.studentPageItems[i].icon,
              color: Get.currentRoute == RoutePages.studentPageItems[i].route
                  ? AppTheme.colors.drawerItemColor
                  : AppTheme.colors.drawerItemSelectedColor,
              size: 21.0,
            ),
            title: Text(
              RoutePages.studentPageItems[i].name.tr,
              overflow: TextOverflow.ellipsis,
              style: Get.textTheme.displayLarge?.copyWith(
                color: Get.currentRoute == RoutePages.studentPageItems[i].route
                    ? AppTheme.colors.drawerItemColor
                    : AppTheme.colors.drawerItemSelectedColor,
                fontSize: 16,
                fontFamily: 'Montserrat',
              ),
            ),
            onTap: () {
              if (GetPlatform.isWeb) {
                if (RoutePages.studentPageItems[i].name == 'Home') {
                  Get.offAllNamed(RoutePages.studentPageItems[i].route);
                } else {
                  Get.toNamed(RoutePages.studentPageItems[i].route);
                }
              } else {
                Get.offAllNamed(RoutePages.studentPageItems[i].route);
              }
            },
          ),
        ),
      ));
      if (i != RoutePages.studentPageItems.length - 1) {
        menuItems.add(Divider(
          color: Get.theme.primaryColorLight,
        ));
      }
    }
    return menuItems;
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        primary: false,
        child: Column(children: _buildMenuItems()),
      ),
    );
  }
}
